const totalNameForm = {
	identityCard: '身份证号',
	name: '姓名',
	tel: '联系电话',
	sex: '性别',
	birthday: '出生日期',
	maritalStatus: '婚姻情况',
	registeredPermanentResidence: '户籍所在地',
	residentialAddress: '居住地址',
	urgentName: '紧急联络人',
	urgentTel: '紧急联络人电话',
	local: '应聘地点',
	position: '应聘岗位',
	salaryExpectation: '期望薪资',
	fastestWorkTime: '最快到岗时间',
	learnStartTime: '最高学历开始时间',
	learnEndTime: '最高学历毕业时间',
	schoolName: '学校名称',
	examinationType: '统考/自考',
	educationList: '学历',
	major: '专业',
	graduateType: '毕业',
	nation: '民族',
	stature: '身高',
	weight: '体重',
	eMail: '邮箱',
	certificateLevel: '会计证级别',
	englishLevel: '英语级别',
	selfComment: '自我评价',
	specialty: '特长',
	// openBank: '开户行',
	// accountNumber: '银行卡号'
};
app = new Vue({
	el: "#app",
	data() {
		return {
			styles: 'invisible',
			showPicker: false,
			showLocalPicker: false,
			columns: POSITIONTYPE,
			localcolumns: LOCALTYPE,
			timeValueTemp: '',
			timeValueLearnStart: '请选择时间',
			timeValueLearnEnd: '请选择时间',
			timeValueFast: '请选择时间',
			timeValueBirthday: '请选择时间',
			temp: '',
			isLoadingShow: true,
			currentDate: new Date(),
			className: '',
			showbirthday: false,
			showfastest: false,
			showstart: false,
			showend: false,
			minbirthDate: new Date(1975, 0, 1),
			minDate: new Date(1980, 0, 1),
			minfastDate: new Date(),
			maxDate: new Date(2030, 0, 31),
			active: 0,
			activeName: '1',
			deepForm: {

			},
			checksignshow: false,
			show: false,
			isShow: false,
			showsign: true,
			className: '',
			timeValueTemp: '',
			timeValueStart: '请选择时间',
			timeValueEnd: '请选择时间',
			timeValueStart1: '请选择时间',
			timeValueEnd1: '请选择时间',
			showstart: false,
			showend: false,
			showstart1: false,
			showend1: false,
			minDate: new Date(1980, 0, 1),
			maxDate: new Date(2030, 0, 31),
			saveDisable: false,
			saveCan: false,
			submitDisable: true,
			isLoadingShow: true,
			active: 0,
			activeName: '1',
			deepForm: {

			},
			totalForm: {
				identityCard: '',
				name: '',
				sex: '男',
				birthday: '',
				maritalStatus: '已婚',
				tel: '',
				registeredPermanentResidence: '',
				residentialAddress: '',
				urgentName: '',
				urgentTel: '',
				local:'',
				position: '',
				salaryExpectation: '',
				fastestWorkTime: '',
				learnStartTime: '',
				learnEndTime: '',
				schoolName: '',
				examinationType: '统考',
				educationList: '',
				major: '',
				graduateType: '毕业',
				perfectFlag: '1',
				nation: '',
				stature: '',
				weight: '',
				eMail: '',
				health: [{
						"label": "是否患有严重的心脏疾病、高血压、哮喘等易突发性疾病？",
						"value": "否"
					},
					{
						"label": "是否患有乙肝、肝炎、肺结核、艾滋等不适合参加公众密切交往的疾病?",
						"value": "否"
					},
					{
						"label": "是否患有严重腰、颈椎疾病或近期做过重大手术?",
						"value": "否"
					},
					{
						"label": "是否患有癌症、肿瘤等其他疾病?",
						"value": "否"
					},
					{
						"label": "是否处于孕期、产期或哺乳期?或半年之内有生育计划?",
						"value": "否"
					}
				],
				workexperience: [{
						"workstarttime": "",
						"workendtime": "",
						"companyname": "",
						"post": "",
						"workreferences": "",
						"workreferences_tel": "",
						"workreason": ""
					},
					{
						"workstarttime": "",
						"workendtime": "",
						"companyname": "",
						"post": "",
						"workreferences": "",
						"workreferences_tel": "",
						"workreason": ""
					}
				],
				family: [{
						"fam_relation": "",
						"fam_name": "",
						"fam_company_name": "",
						"fam_age": "",
						"fam_tel": ""
					},
					{
						"fam_relation": "",
						"fam_name": "",
						"fam_company_name": "",
						"fam_age": "",
						"fam_tel": ""
					}, {
						"fam_relation": "",
						"fam_name": "",
						"fam_company_name": "",
						"fam_age": "",
						"fam_tel": ""
					}
				],
				certificateLevel: '',
				englishLevel: '',
				selfComment: '',
				specialty: '',
				dataUrl: '',
				openBank: '空',
				accountNumber: '空'
			},

		}
	},
	methods: {
		onLocalConfirm(value) {
			this.totalForm.local = value;
			this.showLocalPicker = false;
		},
		onConfirm(value) {
			this.totalForm.position = value;
			this.showPicker = false;
		},
		showPopup() {
			this.isLoadingShow = true
			setTimeout(() => {
				this.isLoadingShow = false
			}, 500)
		},
		showPopupLearnStart() {
			this.showstart = true
			this.showPopup()
		},
		showPopupLearnEnd() {
			this.showend = true
			this.showPopup()
		},
		showPopupFast() {
			this.showfastest = true
			this.showPopup()
		},
		showPopupBirthday() {
			this.showbirthday = true
			this.showPopup()
		},
		// 确认选择的时间
		confirmPicker(val) {
			let year = val.getFullYear()
			let month = val.getMonth() + 1
			let day = val.getDate()
			if (month >= 1 && month <= 9) {
				month = `0${month}`
			}
			if (day >= 1 && day <= 9) {
				day = `0${day}`
			}
			this.className = 'timeClass'
			this.timeValueTemp = `${year}-${month}-${day}`
			this.temp = `${year}-${month}-${day}`
		},
		confirmPickerLearnStart(val) {
			this.confirmPicker(val);
			this.totalForm.learnStartTime = this.temp
			this.timeValueLearnStart = this.timeValueTemp
			this.showstart = false
		},
		confirmPickerLearnEnd(val) {
			this.confirmPicker(val);
			this.totalForm.learnEndTime = this.temp
			this.timeValueLearnEnd = this.timeValueTemp
			this.showend = false
		},
		confirmPickerFast(val) {
			this.confirmPicker(val);
			this.totalForm.fastestWorkTime = this.temp
			this.timeValueFast = this.timeValueTemp
			this.showfastest = false
		},
		confirmPickerBirthday(val) {
			this.confirmPicker(val);
			this.totalForm.birthday = this.temp
			this.timeValueBirthday = this.timeValueTemp
			this.showbirthday = false
		},
		saveSign() {
			saveSignature();
			this.saveDisable = true;
			this.submitDisable = false;
			this.showsign = false;
		},
		clearSign() {
			this.saveDisable = false;
			this.submitDisable = true;
			clearCanvas();
		},
		showPopup() {
			this.isLoadingShow = true
			setTimeout(() => {
				this.isLoadingShow = false
			}, 500)
		},
		showPopupStart() {
			this.showstart = true
			this.showPopup()
		},
		showPopupEnd() {
			this.showend = true
			this.showPopup()
		},
		showPopupStart1() {
			this.showstart1 = true
			this.showPopup()
		},
		showPopupEnd1() {
			this.showend1 = true
			this.showPopup()
		},
		// 确认选择的时间
		confirmPicker(val) {
			let year = val.getFullYear()
			let month = val.getMonth() + 1
			let day = val.getDate()
			if (month >= 1 && month <= 9) {
				month = `0${month}`
			}
			if (day >= 1 && day <= 9) {
				day = `0${day}`
			}
			this.className = 'timeClass'
			this.timeValueTemp = `${year}-${month}-${day}`
			this.temp = `${year}-${month}-${day}`
		},
		confirmPickerStart(val) {
			this.confirmPicker(val);
			this.totalForm.workexperience[0].workstarttime = this.temp
			this.timeValueStart = this.timeValueTemp
			this.showstart = false
		},
		confirmPickerEnd(val) {
			this.confirmPicker(val);
			this.totalForm.workexperience[0].workendtime = this.temp
			this.timeValueEnd = this.timeValueTemp
			this.showend = false
		},
		confirmPickerStart1(val) {
			this.confirmPicker(val);
			this.totalForm.workexperience[1].workstarttime = this.temp
			this.timeValueStart1 = this.timeValueTemp
			this.showstart1 = false
		},
		confirmPickerEnd1(val) {
			this.confirmPicker(val);
			this.totalForm.workexperience[1].workendtime = this.temp
			this.timeValueEnd1 = this.timeValueTemp
			this.showend1 = false
		},
		check() {
			const regtel = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
			const regeMail = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
			const regweight = /^(0(\.\d{1}){0,1}|[1-8]\d{1,3}(\.\d{1}){0,1}|9\d{1,2}(\.\d{1}){0,1}|999(\.0){0,1}|.{0})$/;
			const regheight = /^(0{1}|[1-9]\d{0,3}|.{0})$/;
			const regage = /^(?:[1-9][0-9]?|1[01][0-9]|120)$/;
			for (let item in this.totalForm) {
				if (this.totalForm[item] == '' || this.totalForm[item] == null) {
					if (item == "dataUrl"||item == "weight"||item == "stature") {
						// return true
					}else{
							this.$toast(totalNameForm[item] + "不能为空");
							return false;
					}
					// if (item != "dataUrl"||item != "weight"||item != "stature") {
					// 	this.$toast(totalNameForm[item] + "不能为空");
					// 	return false;
					// }
				}
			}
			if (this.totalForm.tel === this.totalForm.urgentTel) {
				this.$toast("个人手机号和紧急联络人手机号一样,请重新输入");
				return false;
			}
			if (this.totalForm.name === this.totalForm.urgentName) {
				this.$toast("姓名和紧急联络人姓名一样,请重新输入");
				return false;
			}
			var item = 0
			// if (this.totalForm.family[item].fam_relation == '' || this.totalForm.family[item].fam_relation == null) {
			// 	this.$toast("家属" + (parseInt(item) + 1) + "关系不能为空");
			// 	return false;
			// }
			// if (this.totalForm.family[item].fam_name == '' || this.totalForm.family[item].fam_name == null) {
			// 	this.$toast("家属" + (parseInt(item) + 1) + "姓名不能为空");
			// 	return false;
			// }
			// if (this.totalForm.family[item].fam_company_name == '' || this.totalForm.family[item].fam_company_name == null) {
			// 	this.$toast("家属" + (parseInt(item) + 1) + "单位名称不能为空");
			// 	return false;
			// }
			// if (this.totalForm.family[item].fam_age == '' || this.totalForm.family[item].fam_age == null) {
			// 	this.$toast("家属" + (parseInt(item) + 1) + "年龄不能为空");
			// 	return false;
			// }
			// if (!regage.test(this.totalForm.family[item].fam_age)) {
			// 	this.$toast("家属" + (parseInt(item) + 1) + "年龄格式不对");
			// 	return false;
			// }
			// if (this.totalForm.family[item].fam_tel == '' || this.totalForm.family[item].fam_tel == null) {
			// 	this.$toast("家属" + (parseInt(item) + 1) + "电话不能为空");
			// 	return false;
			// }
			// if (!regtel.test(this.totalForm.family[item].fam_tel)) {
			// 	this.$toast("家属" + (parseInt(item) + 1) + "电话格式不对");
			// 	return false;
			// }

			this.styles = 'visible'
			this.$toast("输入正确，请签名登记");
		},
		async update() {
			this.check()
			if (this.saveCan == false) {
				this.$toast("请先保存签名在提交")
				return;
			}

			for (let item in this.totalForm.family) {
				for (var key in this.totalForm.family[item]) {
					this.totalForm.family[item][key] = html2Escape(this.totalForm.family[item][key])
				}
			}

			for (let item in this.totalForm.workexperience) {
				for (var key in this.totalForm.workexperience[item]) {
					this.totalForm.workexperience[item][key] = html2Escape(this.totalForm.workexperience[item][key])
				}
			}
			this.totalForm.health = JSON.stringify(this.totalForm.health).replace(/'/g, '"')
			this.totalForm.workexperience = JSON.stringify(this.totalForm.workexperience).replace(/'/g, '"')
			this.totalForm.family = JSON.stringify(this.totalForm.family).replace(/'/g, '"')
			this.submitDisable = true;
			try {
				let res = await axios.put('api/registration/update', this.totalForm);
				if (res.code === 200) {
					this.totalForm.health = JSON.parse(this.totalForm.health)
					this.totalForm.workexperience = JSON.parse(this.totalForm.workexperience)
					this.totalForm.family = JSON.parse(this.totalForm.family)
					this.$toast("修改成功");
				} else {
					this.$toast("后端异常");
					this.submitDisable = false;
				}
			} catch (e) {
				this.$toast("系统异常");
				this.submitDisable = false;
			}
		},
		async checktel() {
			this.findexist()
		},

		async findexist() {
			console.log(this.totalForm)
			try {
				let res = await axios.post('api/registration/query', this.totalForm);
				if (res.code === 200) {
					if (res.total == 0) {} else if (res.total == 1) {
						if (res.data[0].health == null || res.data[0].health == '') {
							this.totalForm.health = JSON.stringify(this.totalForm.health).replace(/'/g, '"')
							var temphealth = JSON.parse(this.totalForm.health)
						} else {
							var temphealth = JSON.parse(res.data[0].health);
						}

						if (res.data[0].workexperience == null || res.data[0].workexperience == '') {
							this.totalForm.workexperience = JSON.stringify(this.totalForm.workexperience).replace(/'/g, '"')
							var tempworkexperience = JSON.parse(this.totalForm.workexperience)
						} else {
							var tempworkexperience = JSON.parse(res.data[0].workexperience);
						}

						if (res.data[0].family == null || res.data[0].family == '') {
							this.totalForm.family = JSON.stringify(this.totalForm.family).replace(/'/g, '"')
							var tempfamily = JSON.parse(this.totalForm.family)
						} else {
							var tempfamily = JSON.parse(res.data[0].family);
						}
						this.totalForm = deepCopy(res.data[0])
						this.timeValueBirthday = res.data[0].birthday
						this.timeValueFast = res.data[0].fastestWorkTime
						this.timeValueLearnStart = res.data[0].learnStartTime
						this.timeValueLearnEnd = res.data[0].learnEndTime
						this.totalForm.health = temphealth
						this.totalForm.workexperience = tempworkexperience
						this.totalForm.family = tempfamily
						this.timeValueStart = this.totalForm.workexperience[0].workstarttime == "" ? "请选择时间" : this.totalForm.workexperience[
							0].workstarttime
						this.timeValueEnd = this.totalForm.workexperience[0].workendtime == "" ? "请选择时间" : this.totalForm.workexperience[
							0].workendtime
						this.timeValueStart1 = this.totalForm.workexperience[1].workstarttime == "" ? "请选择时间" : this.totalForm.workexperience[
							1].workstarttime
						this.timeValueEnd1 = this.totalForm.workexperience[1].workendtime == "" ? "请选择时间" : this.totalForm.workexperience[
							1].workendtime
					}
				} else {
					this.$toast("后端异常");
				}
			} catch (e) {
				this.$toast("系统异常");
			}

		},
		onClick() {

			this.isShow = !this.isShow

		},


	},
	async mounted() {
		this.findexist()
	},
	created() {
		window.sessionStorage.getItem("data");
		var url = location.search;

		strs = url.split("=");
		this.totalForm.identityCard = strs[1] == undefined ? this.totalForm.identityCard : strs[1];
	}
});
